/**
 * 
 */
package fr.utbm.gi.vi51.slizers.framework.util;

import javax.vecmath.Tuple2i;

/**
 * A 2-element vector that is represented by signed integer x,y coordinates.
 * 
 * @author Tarik Belabbas
 * 
 */
public class Vector2i extends Tuple2i implements java.io.Serializable
{
	/**
	 * Version number associated to the serializable class.
	 */
	private static final long	serialVersionUID	= -7266503650523036911L;

	/**
	 * Constructs and initializes a Vector2i from the specified xy coordinates.
	 * 
	 * @param x the x coordinate
	 * @param y the y coordinate
	 */
	public Vector2i( int x, int y )
	{
		super( x, y );
	}

	/**
	 * Constructs and initializes a Vector2i from the specified array.
	 * 
	 * @param v the array of length 2 containing xy in order
	 */
	public Vector2i( int[] v )
	{
		super( v );
	}

	/**
	 * Constructs and initializes a Vector2i from the specified Vector2i.
	 * 
	 * @param v1 the Vector2i containing the initialization x y data
	 */
	public Vector2i( Vector2i v1 )
	{
		super( v1 );
	}

	/**
	 * Constructs and initializes a Vector2i from the specified Vector2i.
	 * 
	 * @param t1 the Tuple2i containing the initialization x y data
	 */
	public Vector2i( Tuple2i t1 )
	{
		super( t1 );
	}
	
	/**
	 * Constructs and initializes a Vector2i to (0,0).
	 */
	public Vector2i()
	{
		super();
	}

	/**
	 * Computes the dot product of the this vector and vector v1.
	 * 
	 * @param v1 the other vector
	 */
	public final int dot( Vector2i v1 )
	{
		return ( this.x * v1.x + this.y * v1.y );
	}

	/**
	 * Returns the length of this vector.
	 * 
	 * @return the length of this vector
	 */
	public final float length()
	{
		return ( float ) Math.sqrt( this.x * this.x + this.y * this.y );
	}

	/**
	 * Returns the squared length of this vector.
	 * 
	 * @return the squared length of this vector
	 */
	public final float lengthSquared()
	{
		return ( this.x * this.x + this.y * this.y );
	}

	/**
	 * Returns the angle in radians between this vector and the vector
	 * parameter; the return value is constrained to the range [0,PI].
	 * 
	 * @param v1 the other vector
	 * @return the angle in radians in the range [0,PI]
	 */
	public final float angle( Vector2i v1 )
	{
		double vDot = this.dot( v1 ) / ( this.length() * v1.length() );
		if ( vDot < -1.0 )
			vDot = -1.0;
		if ( vDot > 1.0 )
			vDot = 1.0;
		return ( ( float ) ( Math.acos( vDot ) ) );
	}

}
